<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" th:href="@{lib/layui-v2.6.3/css/layui.css}" media="all">
  <link rel="stylesheet" th:href="@{/css/public.css}" media="all">
</head>
<body>
<div class="layuimini-container">
  <div class="layuimini-main">


    <script type="text/html" id="toolbarDemo">
      <div class="layui-btn-container">

      </div>
    </script>

    <table id="currentTableId" lay-filter="currentTableFilter"></table>

    <script type="text/html" id="currentTableBar">

    </script>

  </div>
</div>
<script th:src="@{/lib/layui-v2.6.3/layui.js}" charset="utf-8"></script>
<script th:inline="javascript">
  layui.use(['form', 'table'], function () {
    var $ = layui.jquery,
            form = layui.form,
            table = layui.table;
    table.on('tool(currentTableFilter)', function (obj) {
      var product = obj.data;
      if (obj.event === 'edit') {

        var index = layer.open({
          title: '编辑商品',
          type: 2,
          shade: 0.2,
          maxmin:true,
          shadeClose: true,
          area: ['70%', '80%'],
          content: '/admin/product/update/html?categoryId='+order.category_id,
          success:function (layero,index) {
            var body = layer.getChildFrame('body', index);
            //将选中的数据的id传到编辑页面的隐藏域，便于根据ID修改数据
            body.find("#productId").val(order.product_id);
            body.find("#productName").val(order.product_name);
            body.find("#productTitle").val(order.product_title);
            body.find("#productPrice").val(order.product_price);
            body.find("#productSellingPrice").val(order.product_selling_price);
            body.find("#productNum").val(order.product_num);
            body.find("#productSales").val(order.product_sales);
            body.find("#productIntro").val(order.product_intro);
            body.find("#productPicture").val(order.product_picture);
          }
        });
        $(window).on("resize", function () {
          layer.full(index,userInfo);
        });
        return false;
      } else if (obj.event === 'delete') {
        layer.confirm('确定删除数据?', function (index) {

          // console.log(obj.data.userId)
          $.post({
            url:"/admin/product/remove",
            data:{
              productId:obj.data.product_id
            },
            success:function (resp){
               layer.msg(resp.msg);
               if (resp.code == "001"){

                 //obj.del();//删除数据
                 table.reload('currentTableId', {
                   page: {
                     curr: 1,
                     limit:15
                   }
                 }, 'data');
               }



            },
            field:function (resp) {

            }
          })
          layer.close(index);
        });
      }
    });
  })
</script>
<script th:inline="none">
  // var cpxPath=[[${"/"}]]

  layui.use(['form', 'table'], function () {
    var $ = layui.jquery,
            form = layui.form,
            table = layui.table;
    table.render({
      elem: '#currentTableId',
      url: '/admin/order/list',
      toolbar: '#toolbarDemo',
      defaultToolbar: ['filter', 'exports', 'print', {
        title: '提示',
        layEvent: 'LAYTABLE_TIPS',
        icon: 'layui-icon-tips'
      }],
      cols: [[
        {field: 'order_id', width: 150, title: '订单编号', sort: true},
        {field: 'user_id', width: 80, title: '用户编号', sort: true},
        {field: 'product_num', width: 80, title: '商品种类',sort:true ,templet:function (d) {
            return d.product_num + " 种";
          } },
        {field: 'order_num', width: 80, title: '商品数量',sort:true ,templet:function (d) {
            return d.order_num + " 件";
          } },
        {field: 'order_price', title: '订单金额', width:130,sort:true ,templet:function (d) {
           return d.order_price + " 元";
          }},
        {field: 'order_time', title: '订单时间', sort:true ,templet:function (d) {
            return layui.util.toDateString(d.order_time, 'yyyy年MM月dd日 HH:mm:ss');
          }}
      ]],
      limits: [10, 15, 20, 25, 50, 100],
      limit: 15,
      response: {
        statusName: 'code' //规定数据状态的字段名称，默认：code
        ,statusCode: "001" //规定成功的状态码，默认：0
        ,msgName: 'msg' //规定状态信息的字段名称，默认：msg
        ,countName: 'total' //规定数据总数的字段名称，默认：count
        ,dataName: 'data' //规定数据列表的字段名称，默认：data
      },
      request: {
        pageName: 'currentPage' //页码的参数名称，默认：page
        ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
      },
      page: true,
      skin: 'line'
    });

    // 监听搜索操作
    form.on('submit(data-search-btn)', function (data) {
      var key = data.field.goodsName;
      //执行搜索重载
      table.reload('currentTableId', {
        page: {
          curr: 1
        }
        , where: {
          search: key
        }
      }, 'data');

      return false;
    });

    /**
     * toolbar监听事件
     */
    table.on('toolbar(currentTableFilter)', function (obj) {
      if (obj.event === 'add') {  // 监听添加操作
        var index = layer.open({
          title: '添加用户',
          type: 2,
          shade: 0.2,
          maxmin:true,
          shadeClose: true,
          area: ['70%', '80%'],
          content: '/admin/product/save/html',
        });
        $(window).on("resize", function () {
          layer.full(index);
        });
      } else if (obj.event === 'delete') {  // 监听删除操作
        var checkStatus = table.checkStatus('currentTableId')
                , data = checkStatus.data;
        layer.alert(JSON.stringify(data));
      }
    });

    //监听表格复选框选择
    table.on('checkbox(currentTableFilter)', function (obj) {
      console.log(obj)
    });

  });
</script>

</body>
</html>